package order;

import enums.ReportUserType;
import models.BaseModel;
import models.merchant.Merchant;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/9/7.
 */
@Entity
@Table(name = "report_remark")
public class ReportRemark extends BaseModel {

    /**
     * 用户投诉备注
     */
    @Column(name = "report_remarks")
    public String reportRemarks;


    /**
     * 用户投诉图片
     */
    @Column(name = "report_image")
    public String reportImage;

    /**
     * 投诉时间
     */
    @Column(name = "report_date")
    public Date reportDate;

    /**
     * 投诉单ID
     */
    @JoinColumn(name = "report_id", nullable = true)
    @ManyToOne
    public Report report;

    /**
     * 投诉用户类型
     */
    @Column(name = "report_user_type")
    @Enumerated(EnumType.STRING)
    public ReportUserType reportUserType;


    /**
     * 投诉用户ID
     */
    @Column(name = "report_user")
    public Long reportUser;


    /**
     * 商户查询 被投诉订单
     * @param merchant
     * @return
     */
    public static List<ReportRemark> getListByMerchantAndReport(Merchant merchant,Report report) {
        return ReportRemark.find(" report_user = ?  and report.id = ?", merchant.id,report.id).fetch();
    }

    /**
     * 商户查询 被投诉订单
     * @param merchant
     * @return
     */
    public static ReportRemark getByMerchantAndReport(Merchant merchant,Report report) {
        return ReportRemark.find("  report.id = ? and  reportUserType = ?   ", report.id,ReportUserType.USER).first();
    }

    /**
     * 商户查询 被投诉订单
     * @param merchant
     * @return
     */
    public static List<ReportRemark> getBydReport(Report report) {
        return ReportRemark.find("  report.id = ?   ", report.id).fetch();
    }
}
